<!--
 * @Author: your name
 * @Date: 2021-12-15 16:03:27
 * @LastEditTime: 2021-12-16 09:26:51
 * @LastEditors: lsy
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \iccdemov2\src\views\Home\Iframes.vue
-->
<template>
  <iframe
    :id="iframeId"
    :src="src"
    class="wpms-frame-style"
    frameborder="0"
    :style="{ height: clientHeight + 'px' }"
  ></iframe>
</template>
<script>
export default {
  props: ["iframeId", "src", "clientHeight", "btnValue"],
  mounted() {
    this.getMenuBtn();
  },
  methods: {
    //获取按钮权限
    getMenuBtn() {
      let basePath = ''
      if (!window.location.origin) {
        basePath = window.location.protocol + '//' + window.location.host + '/'
      } else {
        basePath = window.location.origin + '/' + `${this.src}`
      }
      let th = this;
      var iframe = document.getElementById(`${th.iframeId}`);
      if (iframe.attachEvent) {
        iframe.attachEvent("onload", function () {
          //iframe加载完成后你需要进行的操作
          iframe.contentWindow.postMessage({
            name: 'btnControl',
            value: th.btnValue
          }, basePath)
        });
      } else {
        iframe.onload = function () {
          //iframe加载完成后你需要进行的操作
          iframe.contentWindow.postMessage({
            name: 'btnControl',
            value: th.btnValue
          }, basePath)
        };
      }
    }
  }
}
</script>
<style>
.wpms-frame-style {
  width: 100%;
}
</style>